package com.zlp.mall.upms.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zlp.mall.core.utils.api.Pager;
import com.zlp.mall.core.utils.api.Result;
import com.zlp.mall.log.annotation.SysLog;
import com.zlp.mall.upms.dto.req.UserCreateReq;
import com.zlp.mall.upms.dto.resp.UserQueryReq;
import com.zlp.mall.upms.dto.resp.UserResp;
import com.zlp.mall.upms.service.UserService;
import com.zlp.mall.upms.dto.CacheInfo;
import com.zlp.mall.upms.dto.req.LoginUserReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * <p>
 * 管理用户表 前端控制器
 * </p>
 *
 * @author Zou.LiPing
 * @since 2021-03-11
 */
@RestController
@RequestMapping("/user")
@AllArgsConstructor
@Api(value = "user", tags = "用户模块")
public class UserController {

    private final UserService userService;

    @ApiOperation( "登录")
    @PostMapping(value = "login")
    @ApiOperationSupport(order = 1)
    public Result<CacheInfo> login(@Valid @RequestBody LoginUserReq loginReq){

        return Result.success(userService.login(loginReq));
    }


    @PostMapping("getUserPage")
    @ApiOperation("获取用户列表")
    @ApiOperationSupport(order = 2)
    public Result<Pager<UserResp>> getUserPage(@Valid @RequestBody UserQueryReq userQueryReq){

        return Result.success(userService.getUserPage(userQueryReq));
    }

    @GetMapping("getUserInfo")
    @ApiOperation("获取用户信息")
    @ApiOperationSupport(order = 3)
    public Result<UserResp> getUserInfo(
            @RequestParam(value="userId" )  @ApiParam(name="userId",value="用户ID",required = true) Long userId
    ){

        return Result.success(userService.getUserInfo(userId));
    }
    @SysLog("添加用户")
    @PostMapping("addUser")
    @ApiOperation("添加用户")
    public Result addUser(@Valid@RequestBody UserCreateReq userCreateReq) {
        return Result.success(userService.addUser(userCreateReq));
    }


}

